<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="内容" prop="cmsContentId">
									<el-input v-model="form.cmsContentId" placeholder="请输入内容" clearable></el-input>
								</el-form-item>
								<el-form-item label="类型" prop="contentTypeId">
									<el-input v-model="form.contentTypeId" placeholder="请输入类型" clearable></el-input>
								</el-form-item>
								<el-form-item label="部门店铺" prop="departmentId">
									<el-input v-model="form.departmentId" placeholder="请输入部门店铺" clearable></el-input>
								</el-form-item>
								<el-form-item label="个人用户发布" prop="customerId">
									<el-input v-model="form.customerId" placeholder="请输入个人用户发布" clearable></el-input>
								</el-form-item>
								<el-form-item label="新闻分类路径" prop="typePath">
									<el-input v-model="form.typePath" placeholder="请输入新闻分类路径" clearable></el-input>
								</el-form-item>
								<el-form-item label="发布区域路径" prop="regionPath">
									<el-input v-model="form.regionPath" placeholder="请输入发布区域路径" clearable></el-input>
								</el-form-item>
								<el-form-item label="发布-电商产品栏目路径" prop="categoryPath">
									<el-input v-model="form.categoryPath" placeholder="请输入发布-电商产品栏目路径" clearable></el-input>
								</el-form-item>
								<el-form-item label="内容编码" prop="contentCode">
									<el-input v-model="form.contentCode" placeholder="请输入内容编码" clearable></el-input>
								</el-form-item>
								<el-form-item label="标题" prop="contentTitle">
									<el-input v-model="form.contentTitle" placeholder="请输入标题" clearable></el-input>
								</el-form-item>
								<el-form-item label="副标题" prop="subtitle">
									<el-input v-model="form.subtitle" placeholder="请输入副标题" clearable></el-input>
								</el-form-item>
								<el-form-item label="1已发布 2待审核 0失效 3审核不通过 4过期(已下架)" prop="display">
									<el-input v-model="form.display" placeholder="请输入1已发布 2待审核 0失效 3审核不通过 4过期(已下架)" clearable></el-input>
								</el-form-item>
								<el-form-item label="内容" prop="contentValue">
									<el-input v-model="form.contentValue" placeholder="请输入内容" clearable></el-input>
								</el-form-item>
								<el-form-item label="发行时间" prop="issueTime">
									<el-input v-model="form.issueTime" placeholder="请输入发行时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="过期下架时间" prop="expireTime">
									<el-input v-model="form.expireTime" placeholder="请输入过期下架时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="创建时间" prop="createTime">
									<el-input v-model="form.createTime" placeholder="请输入创建时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="seo引擎关键字" prop="keyWords">
									<el-input v-model="form.keyWords" placeholder="请输入seo引擎关键字" clearable></el-input>
								</el-form-item>
								<el-form-item label="seo引擎描述" prop="description">
									<el-input v-model="form.description" placeholder="请输入seo引擎描述" clearable></el-input>
								</el-form-item>
								<el-form-item label="标题宣传媒体" prop="imgUrl">
									<el-input v-model="form.imgUrl" placeholder="请输入标题宣传媒体" clearable></el-input>
								</el-form-item>
								<el-form-item label="1 0是否有媒体图片" prop="withMedia">
									<el-input v-model="form.withMedia" placeholder="请输入1 0是否有媒体图片" clearable></el-input>
								</el-form-item>
								<el-form-item label="是否置顶 购买置顶 按置顶金额降序" prop="isTop">
									<el-input v-model="form.isTop" placeholder="请输入是否置顶 购买置顶 按置顶金额降序" clearable></el-input>
								</el-form-item>
								<el-form-item label="自定义连接" prop="url">
									<el-input v-model="form.url" placeholder="请输入自定义连接" clearable></el-input>
								</el-form-item>
								<el-form-item label="1pc端 2移动客户端 3综合客户端" prop="toType">
									<el-input v-model="form.toType" placeholder="请输入1pc端 2移动客户端 3综合客户端" clearable></el-input>
								</el-form-item>
								<el-form-item label="经度" prop="longitude">
									<el-input v-model="form.longitude" placeholder="请输入经度" clearable></el-input>
								</el-form-item>
								<el-form-item label="纬度" prop="latitude">
									<el-input v-model="form.latitude" placeholder="请输入纬度" clearable></el-input>
								</el-form-item>
								<el-form-item label="降序" prop="seq">
									<el-input v-model="form.seq" placeholder="请输入降序" clearable></el-input>
								</el-form-item>
								<el-form-item label="收藏数量" prop="collectionCount">
									<el-input v-model="form.collectionCount" placeholder="请输入收藏数量" clearable></el-input>
								</el-form-item>
								<el-form-item label="称赞数量" prop="tagCount">
									<el-input v-model="form.tagCount" placeholder="请输入称赞数量" clearable></el-input>
								</el-form-item>
								<el-form-item label="评论数量" prop="commentCount">
									<el-input v-model="form.commentCount" placeholder="请输入评论数量" clearable></el-input>
								</el-form-item>
								<el-form-item label="查阅数量" prop="lookCount">
									<el-input v-model="form.lookCount" placeholder="请输入查阅数量" clearable></el-input>
								</el-form-item>
								<el-form-item label="会员等级限制" prop="membershipLevel">
									<el-input v-model="form.membershipLevel" placeholder="请输入会员等级限制" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	import contentAPI from '@/api/content/cmsContent';
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: ''
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					cmsContentId: "",
					contentTypeId: "",
					departmentId: "",
					customerId: "",
					typePath: "",
					regionPath: "",
					categoryPath: "",
					contentCode: "",
					contentTitle: "",
					subtitle: "",
					display: "",
					contentValue: "",
					issueTime: "",
					expireTime: "",
					createTime: "",
					keyWords: "",
					description: "",
					imgUrl: "",
					withMedia: "",
					isTop: "",
					url: "",
					toType: "",
					longitude: "",
					latitude: "",
					seq: "",
					collectionCount: "",
					tagCount: "",
					commentCount: "",
					lookCount: "",
					membershipLevel: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await contentAPI.cmsContent.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.cmsContentId = data.cmsContentId;
				this.form.contentTypeId = data.contentTypeId;
				this.form.departmentId = data.departmentId;
				this.form.customerId = data.customerId;
				this.form.typePath = data.typePath;
				this.form.regionPath = data.regionPath;
				this.form.categoryPath = data.categoryPath;
				this.form.contentCode = data.contentCode;
				this.form.contentTitle = data.contentTitle;
				this.form.subtitle = data.subtitle;
				this.form.display = data.display;
				this.form.contentValue = data.contentValue;
				this.form.issueTime = data.issueTime;
				this.form.expireTime = data.expireTime;
				this.form.createTime = data.createTime;
				this.form.keyWords = data.keyWords;
				this.form.description = data.description;
				this.form.imgUrl = data.imgUrl;
				this.form.withMedia = data.withMedia;
				this.form.isTop = data.isTop;
				this.form.url = data.url;
				this.form.toType = data.toType;
				this.form.longitude = data.longitude;
				this.form.latitude = data.latitude;
				this.form.seq = data.seq;
				this.form.collectionCount = data.collectionCount;
				this.form.tagCount = data.tagCount;
				this.form.commentCount = data.commentCount;
				this.form.lookCount = data.lookCount;
				this.form.membershipLevel = data.membershipLevel;
			}
		}
	}
</script>
<style>
</style>
